import modalPage from '@/components/modal-page'
import { ref } from 'vue'
type CallBackFn = (item?: any) => void
export function useModalPage(insertNewCB?: CallBackFn, editCB?: CallBackFn) {
  // 拿到modal的ref对象
  const modalRef = ref<InstanceType<typeof modalPage>>()
  // 对新建用户的处理
  const insertNewClick = () => {
    defaultInfo.value = {}
    modalRef.value!.DialogVisible = true
    // 当insertNewCB有值时调用insertNewCB()
    insertNewCB && insertNewCB()
  }

  const defaultInfo = ref({})
  // 将item中的 menu 传出去
  const EditClick = (item: any) => {
    defaultInfo.value = { ...item }
    modalRef.value!.DialogVisible = true
    editCB && editCB(item)
  }
  return {
    modalRef,
    defaultInfo,
    insertNewClick,
    EditClick
  }
}
